package com.example.bookmall.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.bookmall.entity.order.OrderItemVo;
import org.apache.ibatis.annotations.Mapper;
import com.example.bookmall.entity.order.OrderItem;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface OrderItemMapper extends BaseMapper<OrderItem> {


    /**
     * 根据订单ID查询订单明细VO列表（含图书信息）
     */
    @Select("SELECT " +
            "oi.item_id AS itemId, " +
            "oi.order_id AS orderId, " +
            "oi.book_id AS bookId, " +
            "b.title AS booktitle, " +
            "b.cover_url AS bookcover, " +
            "oi.price, " +
            "oi.quantity, " +
            "oi.price * oi.quantity AS subtotal " +
            "FROM order_item oi " +
            "LEFT JOIN book b ON oi.book_id = b.book_id " +
            "WHERE oi.order_id = #{orderId}")
    List<OrderItemVo> listOrderItemsByOrderId(String orderId);
}
